/**
 * 加载页面时候，绑定
 * @param div_id
 * @return
 */
 function getDept(){
	DeptDAOImpl.getALLDept(callBack);
	DutyDAOImpl.getAllDuty(callBack2);
}
function callBack(data){
	var obj2=document.getElementById("dept2");

	DWRUtil.removeAllOptions(obj2);
	DWRUtil.addOptions(obj2,data,"id","name");
	
	
}
function callBack2(data){
	var obj2=document.getElementById("duty2");

	DWRUtil.removeAllOptions(obj2);
	DWRUtil.addOptions(obj2,data,"id","name");
	
}
//记载页面的时候，绑定离职类型。
function getLeaveType(){
	LeaveTypeDAOImpl.getAll(callBack_l);
	}
	function callBack_l(data){
		var obj=document.getElementById("ltype");
		DWRUtil.removeAllOptions(obj);
		DWRUtil.addOptions(obj,data,"id","tye");
		
		
	}

	//查询
    function serch(){
	document.getElementById("form").submit();
}
//提交
    function tijiao(){
    	document.getElementById("tjform").submit();
    }
//浮动
function hideDiv(div_id){
            $("#" + div_id).animate({opacity: "hide" }, 300);
}
function popupDiv(div_id) {
            var div_obj = $("#" + div_id);
            //窗口宽度,高度
            var winWidth = $(window).width();
            var winHeight = $(window).height();
            //弹出的div的宽度,高度
            var popHeight = div_obj.height();
            var popWidth = div_obj.width();
            div_obj.animate({
				 opacity: "show", left: (winWidth-popWidth) / 2, top: (winHeight-popHeight)/2,width:popWidth,height:popHeight}, 300);          
}
$(function() {
            $(".pop_box").easydrag();
            $(".pop_box").setHandler(".pop_box .p_head");
});
//查询条件隐藏时间
function changeselecttype()
{
	if("time"==$("#selecttype").val())
	{
		 $("#other").animate({opacity: "hide" }, 300);
	}else
	{
	 $("#other").animate({opacity: "show" }, 300);
	}
}

//绑定缺员
var idkey;
function update(empno){
	EmpDAOImpl.getIDByEmpno(empno,function(data){
	
		//alert(data);
		idkey=data;
		TansferMag.getEmpById(idkey,function(data2){
			//alert(data2);
			$("#b_dept").val(data2.dept.name);
			$("#beforedept2").html(data2.dept.name);
			$("#b_duty").val(data2.duty.name);
			$("#beforeduty2").html(data2.duty.name);
				
			});
	
	});
}


function updatetransfer(a)
{
	if(!RolePowerManager()){
		return;
	}
	popupDiv('pop_div');
	TansferMag.getById(a,function(data)
			{	
				$("#transferid").val(data.id);
				$("#empno").val(data.emp.empno);
				$("#EmpTransfer").html(data.emp.empno);
				$("#beforedept").val(data.beforedept.name);
				$("#beforedept2").html(data.beforedept.name);
				$("#afterdept").val(data.afterdept.name);
				$("#beforeduty").val(data.beforeduty.name);
				$("#beforeduty2").html(data.beforeduty.name);
				$("#afterduty").val(data.afterduty.name);
				$("#time").val(data.t);
				$("#reason").val(data.reason);
			});
}
function addtransfer(a)
{
	if(!RolePowerManager()){
		return;
	}
	popupDiv('pop_div');
	TansferMag.getEmpById(a,function(data)
			{	
				
				$("#empno").val(data.empno);
				$("#EmpTransfer").html(data.empno);
				$("#b_dept").val(data.dept.name);
				$("#beforedept2").html(data.dept.name);
				$("#b_duty").val(data.duty.name);
				$("#beforeduty2").html(data.duty.name);
			});
}

function addLeave(b){
	if(!RolePowerManager()){
		return;
	}
	popupDiv('pop_div');
	TansferMag.getEmpById(b,function(data)
			{	
				$("#empno").val(data.empno);
				$("#l_empno").html(data.empno);
				
			});
}
//提交审查人事变动的信息
function checkInfo(){
	if($("#transferid").val()==""||$("#empno").val()==""||$("#beforedept").val()==""||$("#afterdept").val()==""||$("#beforeduty").val()==""||
			$("#afterduty").val()==""||$("#time").val()==""||$("#reason").val()==""){
		alert("信息不全，请输入全部信息！");
		return;
	}
	else{
		TansferMag.updateTransfer($("#transferid").val(),$("#beforedept").val(),$("#afterdept").val(),$("#beforeduty").val(),$("#afterduty").val(),
				$("#time").val(),$("#reason").val(),function(data)
				{
				if(data)
				{
					alert("审核通过");
					location.reload();
				}else
					{
					alert("审核失败");
					}
		});
	}
}

//删除调配信息
function Delete(id) {
		if(!RolePowerManager()){
		return;
	}
    if (confirm("你确认删除这条记录吗?")) {
    TansferMag.delTransferByID(id,function(){

    });
    location.reload();
    }
}
    
	function callBack(data){

		var obj=document.getElementById("ltype");
		DWRUtil.removeAllOptions(obj);
		DWRUtil.addOptions(obj,data,"id","tye");
		
		
	}
//删除
	

//证书页面的分页
    function changePageSize_ac()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="serchEmp?pageSize="+pageSize;
    }
//人事变动管理
    function changePageSize_meg()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="Meg_TransferServlet?pageSize="+pageSize;
    }
//serchLeave
    function changePageSize_leave()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="serchLeave?pageSize="+pageSize;
    }
//que
    function changePageSize_que()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="EmpTransfer?pageSize="+pageSize;
    }
//changePageSize_sleave
    function changePageSize_sleave()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="showLeave?pageSize="+pageSize;
    }
//TransferServlet
    function changePageSize_st()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="TransferServlet?pageSize="+pageSize;
    }
//新近员工的分页
    function changePageSize_emp()
    {
    	var pageSize=$("#pageSize").val();
    	location.href="showNewEmp?pageSize="+pageSize;
    }
    
//新增员工
    function getEdu(){
    	
    	EducationManager.getAll(callBack_edu);
    	EduDegreeManager.getAll(callBack_degree);
    	DutyManager.getAllDuty(callBack_duty);
    	DeptDAOImpl.getALLDept(callBack_dept);
    	SkillGradeManager.getAll(callBack_skill);
    	EmpStatusManager.getAllEmpStatus(callBack_st);
	}
	function callBack_edu(data){
		var obj=document.getElementById("educationtype");
		DWRUtil.removeAllOptions(obj);
		DWRUtil.addOptions(obj,data,"id","name");
    }
	function callBack_degree(data){
		var obj=document.getElementById("eduDegreetype");
		DWRUtil.removeAllOptions(obj);
		DWRUtil.addOptions(obj,data,"id","name");
    }
	function callBack_duty(data){
		var obj=document.getElementById("dutytype");
		DWRUtil.removeAllOptions(obj);
		DWRUtil.addOptions(obj,data,"id","name");
    }
	function callBack_dept(data){
		var obj2=document.getElementById("depttype");

		DWRUtil.removeAllOptions(obj2);
		DWRUtil.addOptions(obj2,data,"id","name");
		
	}
	function callBack_skill(data){
		var obj2=document.getElementById("skilltype");

		DWRUtil.removeAllOptions(obj2);
		DWRUtil.addOptions(obj2,data,"id","name");
		
	}
	function callBack_st(data){
		var obj2=document.getElementById("empstatustype");

		DWRUtil.removeAllOptions(obj2);
		DWRUtil.addOptions(obj2,data,"id","name");
		
	}
function addEmp(){
	var name_edit=document.getElementById("name_edit").value;
	var bir_edit=document.getElementById("bir_edit").value;
	var salary_edit=document.getElementById("salary_edit").value;
	var address_edit=document.getElementById("address_edit").value;
	var phone_edit=document.getElementById("phone_edit").value;
	var cid=document.getElementById("cid").value;
	var eid=document.getElementById("eid").value;
	var upload_name=document.getElementsByName("upload_name")[0].value;
	var emp_index=document.getElementById("sex_edit").selectedIndex;
	var sex_edit_value=document.getElementById("sex_edit").options[emp_index].value;
	emp_index=document.getElementById("educationtype").selectedIndex;
	var educationtype_value=document.getElementById("educationtype").options[emp_index].value;
	emp_index=document.getElementById("eduDegreetype").selectedIndex;
	var eduDegreetype_value=document.getElementById("eduDegreetype").options[emp_index].value;
	emp_index=document.getElementById("depttype").selectedIndex;
	var depttype_value=document.getElementById("depttype").options[emp_index].value;
	emp_index=document.getElementById("dutytype").selectedIndex;
	var dutytype_value=document.getElementById("dutytype").options[emp_index].value;
	emp_index=document.getElementById("skilltype").selectedIndex;
	var skilltype_value=document.getElementById("skilltype").options[emp_index].value;
	emp_index=document.getElementById("empstatustype").selectedIndex;
	var empstatustype_value=document.getElementById("empstatustype").options[emp_index].value;
	if(name_edit==""||bir_edit==""||salary_edit==""||address_edit==""||phone_edit==""||cid==""||eid==""
		||sex_edit_value==""||educationtype_value==""||eduDegreetype_value==""||depttype_value==""||dutytype_value==""
		||skilltype_value==""||empstatustype_value==""){
		alert("请填写完信息再提交！");
		return;
	}
	var p4=/(\.jpg)$/i;
	var flag=p4.test(upload_name);
	if(!flag){
		alert("上传的图片格式不是jpg");
		return;
	};
	document.getElementById("empform").submit();
}
//显示新近员工详情
function emp_edit(id) {
	alert(id);
	popupDiv('edit_div');
	TansferMag.getEmpById(id,function(data)
			{	
		alert(data.name);
				$("#name_edit").html(data.name);
				$("#sex").html(data.sex);
				$("#birthday_edit").html(data.t);
				$("#edu").html(data.education.name);
				$("#degree").html(data.eduDegree.name);
				$("#dept").html(data.dept.name);
				$("#duty").html(data.duty.name);
				$("#skill").html(data.skillGrade.name);
				$("#salary_edit").html(data.salary);
				$("#status").html(data.empStatus.name);
				$("#idCardid_edit").html(data.idCardid);
				$("#educationimg_edit").html(data.educationimg);
				$("#address_edit").html(data.address);
				$("#phone_edit").html(data.phone);
			});
}